package com.jbit.examSystem.service.impl;

import com.jbit.examSystem.dao.QuestionDao;
import com.jbit.examSystem.pojo.Question;
import com.jbit.examSystem.pojo.QuestionOe;
import com.jbit.examSystem.param.QuestionSearchParam;
import com.jbit.examSystem.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
public class QuestionServiceImpl implements QuestionService {
    @Autowired
    private QuestionDao questionDao;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    public List<QuestionOe> getAllQuestion(QuestionSearchParam param) {
        List<QuestionOe> questions = questionDao.getAllQuestion(param);
        return questions;
    }

    @Override
    public void addQuestion(Question question) {
        questionDao.addQuestion(question);
    }

    @Override
    public void delete(Integer[] ids) {
        for (int i=0;i<ids.length;i++){
            questionDao.delete(ids[i]);
        }
    }
}
